import common
import unittest

from DCOracle2.dco2 import OracleDate

class test_cursors(common.TestCase):

    def test_selectCursor(self):
        c = self.c
        c.execute('select ename, CURSOR(select ename, mgr from emp) from emp where empno=7902')

        rs = c.fetchall()

        self.assertEqual(len(rs),1)
        c1 = rs[0][1]
        self.assertEqual(c1.fetchall(),
                         [
            ['SMITH', 7902],
            ['ALLEN', 7698],
            ['WARD', 7698],
            ['JONES', 7839],
            ['MARTIN', 7698],
            ['BLAKE', 7839],
            ['CLARK', 7839],
            ['SCOTT', 7566],
            ['KING', None],
            ['TURNER', 7698],
            ['ADAMS', 7788],
            ['JAMES', 7698],
            ['FORD', 7566],
            ['MILLER', 7782]
            ])

    def test_sp_cursor(self):
                        
        findmgr = self.db.procedure.emp_actions.findmgr

        c1 = self.db.cursor()

        c = findmgr(7839,c1)

        self.assertEqual(c1.fetchall(),
                         [
            [7566, 'JONES', 'MANAGER', 7839, OracleDate(1981,4,2,0,0,0), 2975.0, None, 20],
            [7698, 'BLAKE', 'MANAGER', 7839, OracleDate(1981,5,1,0,0,0), 2850.0, None, 30],
            [7782, 'CLARK', 'MANAGER', 7839, OracleDate(1981,6,9,0,0,0), 2450.0, None, 10]
            ])


if __name__ == '__main__':
    unittest.main()
        
